package com.example.demo.controller;


import com.example.demo.pojo.User;
import com.example.demo.service.IUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2022-01-17
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @ApiOperation(value = "登录后返回Token")
    @PostMapping("/login")
    public ResponseEntity<Void> login(User user, HttpServletRequest httpServletRequest)
    {
        return userService.login(user.getUsername(),user.getPassword(),httpServletRequest);
    }


    @ApiOperation(value = "登录后返回Token")
    @PostMapping("/addUser")
    public ResponseEntity<Void> addUser(User user, HttpServletRequest httpServletRequest)
    {
        return userService.add(user.getUsername(),user.getPassword());
    }
}
